package leetcode;

import java.util.Arrays;

/**
 * 6. Z 字形变换
 * @author yujiafan
 * @version 1.0.0
 * @create 2022-12-13
 */
public class LeetCode6 {

    public static String convert(String s, int numRows) {
        if(numRows == 1){
            return s;
        }
        int cur = 0;
        boolean flag = true;
        String[] strList = new String[numRows];
        Arrays.fill(strList, "");
        char[] chars = s.toCharArray();
        for (char aChar : chars) {
            strList[cur] += aChar;
            if (flag) {
                cur++;
            } else {
                cur--;
            }
            if (cur == 0) {
                flag = true;
            }
            if (cur == numRows - 1) {
                flag = false;
            }
        }
        StringBuilder result = new StringBuilder();
        for (String value : strList) {
            result.append(value);
        }
        return result.toString();
    }

    public static void main(String[] args) {
        String paypalishiring = convert("AB", 1);
        System.out.println(paypalishiring);
    }
}
